﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ChatRoom
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["name"] == null && Request.Cookies["password"] == null)
            {
                Response.Redirect("login.aspx");
            }
            if (Application["chatRoom"] == null)
            {
                Application["chatRoom"] = new Panel();
            }
            Panel1.Controls.Add((Panel)Application["chatRoom"]);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            string name = Session["name"].ToString();
            string content = TextBox1.Text;
            string dateTime = DateTime.Now.ToShortDateString();

            Literal literal = new Literal();
            literal.Text = name + " " + dateTime + " " + content + "<br />";

            Panel panel = (Panel)Application["chatRoom"];
            panel.Controls.Add(literal);
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Response.Redirect("login.aspx");
        }
    }
}